package com.keyin.android.net;


public class NetHelper {

	public static StringBuilder addParam(StringBuilder sb, String key,
			String value) {
		if (sb == null) {
			sb = new StringBuilder();
		}
		sb.append(key + "=" + value + "&");
		return sb;
	}

	public static String getHost(String uri) {
		int splitIndex = uri.indexOf("?");
		if (splitIndex < 0) {
			return uri;
		} else {
			return uri.substring(0, splitIndex);
		}
	}

	public static String getParam(String uri) {
		int splitIndex = uri.indexOf("?");
		if (splitIndex < 0) {
			return null;
		} else {
			return uri.substring(splitIndex + 1, uri.length());
		}
	}

	public static String getCMWapHost(String host) {

		if (host.startsWith("http://")){
			host = host.substring(7);
		}
		
		int index = host.indexOf("/");
		if (index < 0){
			return "";
		}
		host = host.substring(index + 1, host.length());
		
		return "http://10.0.0.172/".concat(host);
	}

	public static String getCMWapParam(String host) {
		if (host.startsWith("http://")){
			host = host.substring(7);
		}
		
		int index = host.indexOf("/");
		if (index < 0){
			index = host.length();
		}
		host = host.substring(0, index);
		
		return host;
	}
}
